<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ page import="com.ai.core.util.Configure"%>
<%@ page import="com.ai.wx.util.WeixinUtil"%>
<%@ page import="com.ai.wx.entity.AgentUser"%>
<%@ page import="com.ai.core.constant.GlobalConstant"%>


<% 
Object agentUser = request.getSession().getAttribute("agentUser");
boolean isApproved=false;
String disabled = "";
if(agentUser!=null && ((AgentUser)agentUser).getAgentState() == GlobalConstant.AGENT_STATE_OK){
    isApproved = true;
    disabled = "disabled";
}
%>

<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Cache-control" content="max-age=1700" /> 
<meta name="MobileOptimized" content="320" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">

<script type="text/javascript" src="${ctx}/js/jquery.min.js"></script>
<script type="text/javascript" src="${ctx}/js/common.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<link href="${ctx}/css/box.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/css/agentUser.css" rel="stylesheet" type="text/css" />

<title>推广资格申请</title>
<script>
    
    wx.config({
        debug: false,
        appId: '<%=Configure.getAppId()%>',
        timestamp: ${JsSign.timestamp},
        nonceStr: '${JsSign.nonce}',
        signature: '${JsSign.signature}',
        jsApiList: [
            'checkJsApi',
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'hideMenuItems',
            'showMenuItems',
            'hideAllNonBaseMenuItem',
            'showAllNonBaseMenuItem',  
            'chooseImage',
            'previewImage',
            'uploadImage',
            'downloadImage',
            'getNetworkType', 
            'hideOptionMenu',
            'showOptionMenu',
            'closeWindow',   
          ]
    });

    wx.ready(function () {
         $('.id_card').click(function(){
            
             var fieldName=$(this).data('name');  
             wx.chooseImage({
                 success: function (res) {
                     var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                     if(localIds.length == 1){
                         wx.uploadImage({
                             localId: localIds[0], // 需要上传的图片的本地ID，由chooseImage接口获得
                             isShowProgressTips: 1, // 默认为1，显示进度提示
                             success: function (res) {
                                 var serverId = res.serverId; // 返回图片的服务器端ID 
                                 $('#'+fieldName).val(serverId); 
                             }
                         });
                     }else{
                         alert('每次只能上传一张图片');
                     } 
                 }
            });
         });

         
         $('#newAgentUserBtn').click(function(){
             if($('#userName').val()==''){
                 alert('请填写您的姓名');
                 return;
             }
             if($('#idCard').val()==''){
                 alert('请填写您的身份证号码');
                 return;
             }
             if($('#phone').val()==''){
                 alert('请填写您的手机号码');
                 return;
             }

             if($('#email').val()==''){
                 alert('请填写您的邮箱地址');
                 return;
             }
             if($('#bankCard').val()==''){
                 alert('请填写您的银行卡号');
                 return;
             }
             if($('#bankName').val()==''){
                 alert('请填写您的开户银行');
                 return;
             }
             if($('#idCardPicF').val()==''){
                 alert('请上传您的身份证正面照片');
                 return;
             }
             if($('#idCardPicB').val()==''){
                 alert('请上传您的身份证反面照片');
                 return;
             }
             $.ajax({ 
                 url: '${ctx}/agent/regAgentUser',
                 type: 'POST',
                 data: $('#agentUserForm').serializeObject(),
                 cache:false,
                 dataType:'json',  
                 success: function(data){  
                     if(data.success){
                         alert('申请提交成功，请等待审核');
                         window.location.href='${ctx}/agent/agentApproving'; 
                     }else{
                         alert('申请提交失败，错误原因：'+data.msg);
                     }
                 },
                 error : function(data) {    
                     console.info(data);
                 }    
             });
         });
    });
    
    wx.error(function (res) {
      alert(res.errMsg);
    });
</script>
</head>
<body>
    <form id="agentUserForm" class="ui-form" name="" method="post"
        action="#" id="">
        <fieldset>
            <div id="main"> 
                
                <div class="ui-form-item">
                    <label for="" class="ui-label">姓名 </label> <input class="ui-input"
                        type="text" id="userName" name="userName" maxlength="20" value="${agentUser.userName}" <%=disabled %> > <span
                        class="ui-form-other"></span>
                    <p class="ui-form-explain" style="color:red;">姓名提交后无法修改；请和身份证上的信息保持一致，否则将无法通过审核</p>
                </div>
                
                <div class="ui-form-item">
                    <label for="" class="ui-label">身份证号码 </label> <input
                        class="ui-input" type="text" id="idCard" name="idCard" maxlength="18" value="${agentUser.idCard}" <%=disabled %> > <span
                        class="ui-form-other"></span>
                    <p class="ui-form-explain" style="color:red;">身份证号码提交后无法修改；请和身份证上的信息保持一致，否则将无法通过审核</p>

                </div>
                
                <div class="ui-form-item">
                    <label for="" class="ui-label">手机号码 </label> <input
                        class="ui-input" type="text" id="phone" name="phone" maxlength="11" value="${agentUser.phone}"> <span
                        class="ui-form-other"></span>
                    <p class="ui-form-explain"></p>
                </div>
                <div class="ui-form-item">
                    <label for="" class="ui-label">邮箱 </label> <input class="ui-input"
                        type="text" id="email" name="email" maxlength="50" value="${agentUser.email}"> <span
                        class="ui-form-other"></span>
                    <p class="ui-form-explain"></p>
                </div>
                <div class="ui-form-item">
                    <label for="" class="ui-label">银行卡号 </label> <input
                        class="ui-input" type="text" id="bankCard" name="bankCard" maxlength="19" value="${agentUser.bankCard}">
                    <span class="ui-form-other"></span>
                    <p class="ui-form-explain"></p>
                </div>
                <div class="ui-form-item">
                    <label for="" class="ui-label"> 开户银行 </label> <input
                        class="ui-input" type="text" id="bankName" name="bankName" maxlength="50" value="${agentUser.bankName}">
                    <span class="ui-form-other"></span>
                    <p class="ui-form-explain"></p>
                </div>
                <c:if test="${ empty agentUser || agentUser.agentState != 1}"> 
                    <div class="ui-form-item">
                        <label for="" class="ui-label">证件照片上传</label>
                    </div> 
                     <div class="ui-form-item">
                       <input data-name="idCardPicF"  type="button" class="ui-button ui-button-mgreen id_card" value="上传正面照" <%=disabled %> >
                       <input type="hidde" id="idCardPicF" name="idCardPicF" class="fn-hide"  value="${agentUser.idCardPicF}">
                       <div class="img">  
                       </div>
                       <input type="button" data-name="idCardPicB"  class="ui-button ui-button-mgreen id_card" value="上传反面照" <%=disabled %> >
                       <input type="hidde" id="idCardPicB" name="idCardPicB" class="fn-hide"  value="${agentUser.idCardPicB}">
                       <div class="img">  
                       </div>
                    </div>
                </c:if> 
                
                <c:if test="${not empty agentUser && agentUser.agentState ==1}"> 
                    <div class="ui-form-item">
                    <label for="" class="ui-label">状态 </label> 
                     
                        <input class="ui-input" type="text"   maxlength="50" value="通过审核" disabled>
                        
                    <span class="ui-form-other"></span>
                    <p class="ui-form-explain"></p>
                    </div>
                </c:if> 
                <div class="ui-form-item">
                    <div class="button">
                        <c:if test="${empty agentUser || agentUser.agentState == -1}"> 
                            <input id="newAgentUserBtn" type="button" class="ui-button ui-button-morange" value="提交申请">
                        </c:if>
                        <c:if test="${not empty agentUser && agentUser.agentState == 1}"> 
                            <input id="modifyAgentUserBtn"   type="button" class="ui-button ui-button-morange" disabled="disabled" value="提交修改">
                        </c:if>
                    </div>
                </div>

            </div>
        </fieldset>
    </form>
</body>
</html>




